package com.example.nbshopping.utils;

import android.app.DownloadManager;
import android.util.Log;
import android.view.SurfaceHolder;
/*
*获取网络数据的fragment类，当作父类
**/
import androidx.fragment.app.Fragment;

import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

import java.util.Map;
import java.util.Set;

public class BaseFragment extends Fragment implements Callback.CommonCallback<String> {
    private String TAG = "animee123";
    public void postNetwork(String url, Map<String,String>map){
        RequestParams params=new RequestParams(url);
        //将提交的键值对放入到请求参数当中
        Set<String > keySet=map.keySet();
        for (String key:keySet){
            String val=map.get(key);
            params.addBodyParameter(key,val);
        }
        params.setAsJsonContent(true);
        params.setBodyContentType("application/json;charset=utf-8");
        x.http().post(params,this);
    }
    public void getNetwork(String url){
        RequestParams params=new RequestParams(url);
        x.http().get(params,this);
    }

    @Override
    public void onSuccess(String result) {//获取数据成功时调用此方法
        Log.i(TAG,"onSuccess:result=="+result);
    }

    @Override
    public void onError(Throwable ex, boolean isOnCallback) {//获取数据失败时调用此方法
        Log.i(TAG,"onErroe:ex=="+ex.getMessage());
    }

    @Override
    public void onCancelled(CancelledException cex) {//获取数据失败时调用此方法

    }

    @Override
    public void onFinished() {//获取完成调用此方法

    }
}
